package com.hello.sandbox.fake.service;

import black.android.os.BRServiceManager;
import black.android.service.persistentdata.BRIPersistentDataBlockServiceStub;
import com.hello.sandbox.fake.hook.BinderInvocationStub;
import com.hello.sandbox.fake.service.base.ValueMethodProxy;

/** Created by BlackBox on 2022/3/8. */
public class IPersistentDataBlockServiceProxy extends BinderInvocationStub {

  public static final String NAME = "persistent_data_block";

  public IPersistentDataBlockServiceProxy() {
    super(BRServiceManager.get().getService(NAME));
  }

  @Override
  protected Object getWho() {
    return BRIPersistentDataBlockServiceStub.get()
        .asInterface(BRServiceManager.get().getService(NAME));
  }

  @Override
  protected void inject(Object baseInvocation, Object proxyInvocation) {
    replaceSystemService(NAME);
  }

  @Override
  public boolean isBadEnv() {
    return false;
  }

  @Override
  protected void onBindMethod() {
    super.onBindMethod();
    addMethodHook(new ValueMethodProxy("write", -1));
    addMethodHook(new ValueMethodProxy("read", new byte[0]));
    addMethodHook(new ValueMethodProxy("wipe", null));
    addMethodHook(new ValueMethodProxy("getDataBlockSize", 0));
    addMethodHook(new ValueMethodProxy("getMaximumDataBlockSize", 0));
    addMethodHook(new ValueMethodProxy("setOemUnlockEnabled", 0));
    addMethodHook(new ValueMethodProxy("getOemUnlockEnabled", false));
  }
}
